﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Server.Model;
using Server.DB;

namespace Server.Controller
{
    class LoginController : ILoginController
    {
        private Repository<User> UserRepository;

        public LoginController(Context db)
        {
            UserRepository = new Repository<User>(db);
        }

        /// <summary>
        /// Returns a valid user object
        /// </summary>
        /// <param name="email">Email to get user by</param>
        /// <param name="password">password hash of user</param>
        /// <returns>User object</returns>
        public User Login(string email, string password)
        {
            return UserRepository.SearchFor(u =>
                u.Email.Equals(email) && u.Password.Equals(password)
                ).Single();
        }
    }
}
